__all__ = ["RaceBase"]

class RaceBase(object):
    """
    This object contains information about races descriptions etc and should not
    be used for player specific race information as the Cache object should
    hold all the information regarding that.
    """
    def __init__(self, raceName, typeOfRace=None):
        from wcs.libs.races.popups import skillPopups, raceDescriptions
        
        self.name = raceName
        if typeOfRace is not None:
            if not issubclass(typeOfRace, self.__class__):
                raise ValueError("The type of race '%s' is not a valid option" %
                                                      type(typeOfRace).__name__)
        self.raceType = typeOfRace
        self.skills = {}
        self.skillOrder = []
        self.minLevel = 0
        self.maxLevel = 0
        self.teamLimit = 0
        self.team = None
        self.steamid = set()
        self.authorization = None
        self.lastMenu = None
        self.weaponRestrictions = None

        self.skillsPopup = skillPopups.createPopup(raceName)
        self.racePopup = raceDescriptions.createPopup(raceName)

    def __iter__(self):
        """
        Executed automatically when an instnace of this object is iterated
        throguh. Ensure that we return an iterator to a list of SkillObjects
        in the order in which they were created.

        @return generator An iterator of all the race's skills.
        """
        return [self.skills[x] for x in self.skillOrder].__iter__()

    def __contains__(self, skill):
        """
        Executed when we want to see if a race contains a specific skill.

        @param string skill The name of the skill to test for containment
        @return bool Whether or not the skill exists within this race
        """
        return self.skills.__contains__(skill)

    def __getitem__(self, skill):
        """
        Retrieve the skill object from the race.

        @param string skill The name of the skill to retrieve
        @return Skill A skill object refrenced by the skill name
        """
        return self.skills.__getitem__(skill)